﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Chapter24.Examples
{
    using System.Xml.Linq;

    public class Code09
    {
        public static void BeginEx05()
        {
            var xcust = new XElement("customers",
                new XElement("customer",
                    new XAttribute("ID", "A"),
                    new XAttribute("City", "New York"),
                    new XAttribute("Region", "North America"),
                    new XElement("order",
                        new XAttribute("Item", "Widget"),
                        new XAttribute("Price", 100)
                    ),
                    new XElement("order",
                        new XAttribute("Item", "Tire"),
                        new XAttribute("Price", 200)
                    )
                ),
                new XElement("customer",
                    new XAttribute("ID", "B"),
                    new XAttribute("City", "Mumbai"),
                    new XAttribute("Region", "Asia"),
                    new XElement("order",
                        new XAttribute("Item", "Oven"),
                        new XAttribute("Price", 501)
                    )
                )
            );
            var xmlFileName = @".\example3.xml";
            xcust.Save(xmlFileName);
            var xdoc2 = XElement.Load(xmlFileName);
            Console.WriteLine("Contents of xcust:");
            Console.WriteLine(xcust);
            Console.WriteLine("Press Enter/Return to continue...");
            Console.ReadLine();
        }
    }
}
